package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.ExceptDAO;
import cn.edu.scau.cmi.hombio.dao.ExceptionTypeDAO;
import cn.edu.scau.cmi.hombio.dao.ExceptionTypeEmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.InspectionExceptionDAO;

import cn.edu.scau.cmi.hombio.domain.Except;
import cn.edu.scau.cmi.hombio.domain.ExceptionType;
import cn.edu.scau.cmi.hombio.domain.ExceptionTypeEmployee;
import cn.edu.scau.cmi.hombio.domain.InspectionException;

import cn.edu.scau.cmi.hombio.service.ExceptionTypeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for ExceptionType entities
 * 
 */

@Controller("ExceptionTypeRestController")

public class ExceptionTypeRestController {

	/**
	 * DAO injected by Spring that manages Except entities
	 * 
	 */
	@Autowired
	private ExceptDAO exceptDAO;

	/**
	 * DAO injected by Spring that manages ExceptionType entities
	 * 
	 */
	@Autowired
	private ExceptionTypeDAO exceptionTypeDAO;

	/**
	 * DAO injected by Spring that manages ExceptionTypeEmployee entities
	 * 
	 */
	@Autowired
	private ExceptionTypeEmployeeDAO exceptionTypeEmployeeDAO;

	/**
	 * DAO injected by Spring that manages InspectionException entities
	 * 
	 */
	@Autowired
	private InspectionExceptionDAO inspectionExceptionDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for ExceptionType entities
	 * 
	 */
	@Autowired
	private ExceptionTypeService exceptionTypeService;

	/**
	 * Show all ExceptionType entities
	 * 
	 */
	@RequestMapping(value = "/ExceptionType", method = RequestMethod.GET)
	@ResponseBody
	public List<ExceptionType> listExceptionTypes() {
		return new java.util.ArrayList<ExceptionType>(exceptionTypeService.loadExceptionTypes());
	}

	/**
	* Show all ExceptionTypeEmployee entities by ExceptionType
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/exceptionTypeEmployees", method = RequestMethod.GET)
	@ResponseBody
	public List<ExceptionTypeEmployee> getExceptionTypeExceptionTypeEmployees(@PathVariable Integer exceptiontype_id) {
		return new java.util.ArrayList<ExceptionTypeEmployee>(exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype_id).getExceptionTypeEmployees());
	}

	/**
	* Show all InspectionException entities by ExceptionType
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/inspectionExceptions", method = RequestMethod.GET)
	@ResponseBody
	public List<InspectionException> getExceptionTypeInspectionExceptions(@PathVariable Integer exceptiontype_id) {
		return new java.util.ArrayList<InspectionException>(exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype_id).getInspectionExceptions());
	}

	/**
	* Select an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}", method = RequestMethod.GET)
	@ResponseBody
	public ExceptionType loadExceptionType(@PathVariable Integer exceptiontype_id) {
		return exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype_id);
	}

	/**
	* Delete an existing Except entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/excepts/{except_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeExcepts(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_excepts_id) {
		exceptionTypeService.deleteExceptionTypeExcepts(exceptiontype_id, related_excepts_id);
	}

	/**
	* Create a new Except entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/excepts", method = RequestMethod.POST)
	@ResponseBody
	public Except newExceptionTypeExcepts(@PathVariable Integer exceptiontype_id, @RequestBody Except except) {
		exceptionTypeService.saveExceptionTypeExcepts(exceptiontype_id, except);
		return exceptDAO.findExceptByPrimaryKey(except.getId());
	}

	/**
	* Create a new ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType", method = RequestMethod.POST)
	@ResponseBody
	public ExceptionType newExceptionType(@RequestBody ExceptionType exceptiontype) {
		exceptionTypeService.saveExceptionType(exceptiontype);
		return exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype.getId());
	}

	/**
	* Delete an existing InspectionException entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/inspectionExceptions/{inspectionexception_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeInspectionExceptions(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_inspectionexceptions_id) {
		exceptionTypeService.deleteExceptionTypeInspectionExceptions(exceptiontype_id, related_inspectionexceptions_id);
	}

	/**
	* Save an existing Except entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/excepts", method = RequestMethod.PUT)
	@ResponseBody
	public Except saveExceptionTypeExcepts(@PathVariable Integer exceptiontype_id, @RequestBody Except excepts) {
		exceptionTypeService.saveExceptionTypeExcepts(exceptiontype_id, excepts);
		return exceptDAO.findExceptByPrimaryKey(excepts.getId());
	}

	/**
	* Save an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/exceptionTypeEmployees", method = RequestMethod.PUT)
	@ResponseBody
	public ExceptionTypeEmployee saveExceptionTypeExceptionTypeEmployees(@PathVariable Integer exceptiontype_id, @RequestBody ExceptionTypeEmployee exceptiontypeemployees) {
		exceptionTypeService.saveExceptionTypeExceptionTypeEmployees(exceptiontype_id, exceptiontypeemployees);
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployees.getId());
	}

	/**
	* Save an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType", method = RequestMethod.PUT)
	@ResponseBody
	public ExceptionType saveExceptionType(@RequestBody ExceptionType exceptiontype) {
		exceptionTypeService.saveExceptionType(exceptiontype);
		return exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype.getId());
	}

	/**
	* Save an existing InspectionException entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/inspectionExceptions", method = RequestMethod.PUT)
	@ResponseBody
	public InspectionException saveExceptionTypeInspectionExceptions(@PathVariable Integer exceptiontype_id, @RequestBody InspectionException inspectionexceptions) {
		exceptionTypeService.saveExceptionTypeInspectionExceptions(exceptiontype_id, inspectionexceptions);
		return inspectionExceptionDAO.findInspectionExceptionByPrimaryKey(inspectionexceptions.getId());
	}

	/**
	* Create a new ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/exceptionTypeEmployees", method = RequestMethod.POST)
	@ResponseBody
	public ExceptionTypeEmployee newExceptionTypeExceptionTypeEmployees(@PathVariable Integer exceptiontype_id, @RequestBody ExceptionTypeEmployee exceptiontypeemployee) {
		exceptionTypeService.saveExceptionTypeExceptionTypeEmployees(exceptiontype_id, exceptiontypeemployee);
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee.getId());
	}

	/**
	* Delete an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionType(@PathVariable Integer exceptiontype_id) {
		ExceptionType exceptiontype = exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype_id);
		exceptionTypeService.deleteExceptionType(exceptiontype);
	}

	/**
	* Create a new InspectionException entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/inspectionExceptions", method = RequestMethod.POST)
	@ResponseBody
	public InspectionException newExceptionTypeInspectionExceptions(@PathVariable Integer exceptiontype_id, @RequestBody InspectionException inspectionexception) {
		exceptionTypeService.saveExceptionTypeInspectionExceptions(exceptiontype_id, inspectionexception);
		return inspectionExceptionDAO.findInspectionExceptionByPrimaryKey(inspectionexception.getId());
	}

	/**
	* View an existing Except entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/excepts/{except_id}", method = RequestMethod.GET)
	@ResponseBody
	public Except loadExceptionTypeExcepts(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_excepts_id) {
		Except except = exceptDAO.findExceptByPrimaryKey(related_excepts_id, -1, -1);

		return except;
	}

	/**
	* Delete an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/exceptionTypeEmployees/{exceptiontypeemployee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeExceptionTypeEmployees(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_exceptiontypeemployees_id) {
		exceptionTypeService.deleteExceptionTypeExceptionTypeEmployees(exceptiontype_id, related_exceptiontypeemployees_id);
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* View an existing InspectionException entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/inspectionExceptions/{inspectionexception_id}", method = RequestMethod.GET)
	@ResponseBody
	public InspectionException loadExceptionTypeInspectionExceptions(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_inspectionexceptions_id) {
		InspectionException inspectionexception = inspectionExceptionDAO.findInspectionExceptionByPrimaryKey(related_inspectionexceptions_id, -1, -1);

		return inspectionexception;
	}

	/**
	* Show all Except entities by ExceptionType
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/excepts", method = RequestMethod.GET)
	@ResponseBody
	public List<Except> getExceptionTypeExcepts(@PathVariable Integer exceptiontype_id) {
		return new java.util.ArrayList<Except>(exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype_id).getExcepts());
	}

	/**
	* View an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionType/{exceptiontype_id}/exceptionTypeEmployees/{exceptiontypeemployee_id}", method = RequestMethod.GET)
	@ResponseBody
	public ExceptionTypeEmployee loadExceptionTypeExceptionTypeEmployees(@PathVariable Integer exceptiontype_id, @PathVariable Integer related_exceptiontypeemployees_id) {
		ExceptionTypeEmployee exceptiontypeemployee = exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(related_exceptiontypeemployees_id, -1, -1);

		return exceptiontypeemployee;
	}
}